package com.yfuxdeer.youchat.utils;

import android.app.Application;
import android.util.Log;

import com.alibaba.druid.pool.DruidDataSource;
import com.yfuxdeer.youchat.client.Client;
import com.yfuxdeer.youchat.pojo.User;

import javax.sql.DataSource;

public class Store extends Application {
    private static DataSource dataSource;
    private static final String DRIVER_CLASS_NAME = "com.mysql.cj.jdbc.Driver";
    private static final String URL = "jdbc:mysql://139.159.226.207:3306/youchat";
    private static final String USERNAME = "root";
    private static final String PASSWORD = "password";
    private Client client = null;  //用户客户端
    private User currentUser; //当前登录用户
    public int cacheState = 0;

    static {
        new Thread(new Runnable() {
            @Override
            public void run() {
                DruidDataSource druidDataSource = new DruidDataSource();
                druidDataSource.setDriverClassName(DRIVER_CLASS_NAME);
                druidDataSource.setUrl(URL);
                druidDataSource.setUsername(USERNAME);
                druidDataSource.setPassword(PASSWORD);
                druidDataSource.setMaxWait(5000);
                dataSource = druidDataSource;
                Log.e("Store", "run: " + dataSource);
            }
        }).start();
    }

    private Store() {
    }


    private static class Holder {
        private static final Store instance = new Store();
    }

    public static Store getInstance() {
        return Holder.instance;
    }


    public User getCurrentUser() {
        return currentUser;
    }

    public void setCurrentUser(User currentUser) {
        this.currentUser = currentUser;
    }

    public Client getClient() {
        return client;
    }

    public void setClient(Client client) {
        this.client = client;
    }

    public static DataSource getDataSource() {
        return dataSource;
    }
}
